#include<bits/stdc++.h>
using namespace std;
// #define int long long
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const unordered_set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const unordered_map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const multiset<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
#define ld long double
#define ss second
#define ff first
#define pb push_back
#define mset(m,v) memset(m,v,sizeof(m))
#define nl cout<<"\n";
typedef pair<int, int> pii;
typedef vector<pii> vpii;
#define all(a) (a).begin(), (a).end()
#define f(x,a,b) for(int x=a;x<b;x++)
#define frev(x,a,b) for(int x=a;x>=b;x--)
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define ff first
#define ss second
int N = 2e5+10;
void solve()
{
int n,m;
cin>>n>>m;
int a[n][m], b[n][m];
f(i,0,n) f(j,0,m) cin>>a[i][j];
f(i,0,n) f(j,0,m) cin>>b[i][j];
for(int i=0; i<n; i++)
{
for(int j=1; j<m; j++)
{
if((a[i][j] > a[i][j-1]) && ((b[i][j] > b[i][j-1]))) continue;
else if((b[i][j] > a[i][j-1]) && ((a[i][j] > b[i][j-1])))
{
swap(a[i][j], b[i][j]);
}
else
{
cout<<"Impossible\n";
return;
}
}
}
for(int i=0; i<m; i++)
{
for(int j=1; j<n; j++)
{
if((a[j][i] > a[j-1][i]) && ((b[j][i] > b[j-1][i]))) continue;
else if((b[j][i] > a[j-1][i]) && ((a[j][i] > b[j-1][i])))
{
swap(a[j][i], b[j][i]);
}
else
{
cout<<"Impossible\n";
return;
}
}
}
cout<<"Possible";
}
signed main ()
{
// ios_base::sync_with_stdio(0);
// cin.tie(0);cout.tie(0);
// int t; cin>>t;
// while(t--)
solve();
}
279A - Point on Spiral | 1294D - MEX maximizing |
447A - DZY Loves Hash | 23B - Party |
63D - Dividing Island | 1203E - Boxers |
1547F - Array Stabilization (GCD version) | 358A - Dima and Continuous Line |
1385C - Make It Good | 651A - Joysticks |
1474D - Cleaning | 1588A - Two Arrays |
816A - Karen and Morning | 9D - How many trees |
918B - Radio Station | 15A - Cottage Village |
1737B - Ela's Fitness and the Luxury Number | 1425H - Huge Boxes of Animal Toys |
1737A - Ela Sorting Books | 768C - Jon Snow and his Favourite Number |
1006C - Three Parts of the Array | 81A - Plug-in |
276C - Little Girl and Maximum Sum | 1738D - Permutation Addicts |
1348B - Phoenix and Beauty | 186A - Comparing Strings |
1281A - Suffix Three | 1421C - Palindromifier |
1443A - Kids Seating | 963A - Alternating Sum |